#coding=utf-8
import ctypes
import os

class class_partition(object):

    def get_system_disks(self):
        '''
        获取 系统中当前硬盘 盘符
        :return list 盘符列表:
        '''
        lpBuffer = ctypes.create_string_buffer(78)
        ctypes.windll.kernel32.GetLogicalDriveStringsA(ctypes.sizeof(lpBuffer), lpBuffer)
        #lpBuffer = lpBuffer.raw.decode()
        disks = lpBuffer.raw.decode()
        disk_list = []
        for disk in disks:
            if True == disk.isalpha():
                disk_list.append(disk + ':')
        return disk_list

    def convert_bytes(self, num):
        '''
        将 传入的数值转换 成 KB MB GB
        :param num:
        :return:
        '''

        for x in  ['bytes', 'KB', 'MB', 'GB', 'TB']:
            if num < 1024.0:
                return "%3.1f %s" % (num, x)

            num /= 1024.0


    def get_doc_size(self, path):
        '''
        获取指定文件的大小
        :param path:
        :return:
        '''

        try:
            size = os.path.getsize(path)
            return size
        except Exception as err:
            print(err)

    pass